package com.zx.idc.backend.gui.api.commom.factory;

import com.zx.idc.backend.gui.api.commom.factory.encrypt.AESEncryptionImpl;
import com.zx.idc.backend.gui.api.commom.factory.encrypt.Encrypt;
import com.zx.idc.backend.gui.api.commom.factory.encrypt.NotEncryptionImpl;

import java.util.HashMap;

/**
 * Created by hasee on 2019/2/20.
 */
public class EncryptProvider {
    private static final HashMap<Integer, Encrypt> ENCRYPT_HASH_MAP;

    static {
        ENCRYPT_HASH_MAP = new HashMap<>();
        ENCRYPT_HASH_MAP.put(0, new NotEncryptionImpl());
        ENCRYPT_HASH_MAP.put(1, new AESEncryptionImpl());
    }


    /**
     * 根据指定加密算法类型加密
     * @param encryptAlgorithm 算法类型
     * @param explainText 明文文本
     * @param password 加密密码
     * @param offset 偏移量
     * @return 加密后的字符串
     */
    public static String encrypt(int encryptAlgorithm, byte[] explainText, String password, String offset) {
        Encrypt encrypt = ENCRYPT_HASH_MAP.get(encryptAlgorithm);
        return encrypt.encrypt(explainText, password, offset, true);
    }


    /**
     * 根据指定加密算法类型解密
     * @param encryptAlgorithm 算法类型
     * @param explainText 明文文本
     * @param password 加密密码
     * @param offset 偏移量
     * @return 解密后的字节数组
     */
    public static byte[] decryptAsBytes(int encryptAlgorithm, String explainText, String password, String offset) {
        Encrypt encrypt = ENCRYPT_HASH_MAP.get(encryptAlgorithm);
        return encrypt.decrypt(explainText, password, offset, false);
    }

    /*public static void main(String[] args){
        String text = "8+1Cif20H7ENbYaG3eZtc6EgvAeBRED9ffY5lNyfdkhnPa6Fl9yisOn+2ulTQribSof4IaFRiu6LWh08OT91zKKy+JoCXMnMGVBjlmj/XGygOLN54Ql3oT8r1okBriNqMDFQjE0d5VQz1qyvlfhb8O8PFCzo8eOtqRc30bscHBUqureGcdWYp/1VMTkYgOjpPysETsok1jc3KM7Fi+BvmevcYyBoIZ9AShdsQLGWdN/d5znLFvSWdPVDKafRkVtmtPu8iadQg1hglh80cf6iGOcGcIN8spwa0NXwAk0Dg4k7DKU+BmE4+NJW2YIIjNw4uto87/rE5Yzin3zMhQPLTbumU9kbDogCOop3QpLmcD5pFusZ5hmW5CX6FIQf/R331vrJnut+sfxfQrAADKCLnKsfLg1v4BVIr0U9o+C7M86InEIk6WAdS7C8hpqn7UF3WwdoZ25YKUpyCTgUb7FA5dKrQYEqrXJbR54QmtIgyfCn9C2MyE3SDzB2Frr+zQvTl1TpSW7YAcf+pcJqGWhjg7/AkcNt/pko4jscHnxuQaTi1xNFRxiQOtz6j4Y+EQrk9/mlkuc+fULf2/sQf7hp1ceWa6VYvvtkOgVuMjKx9LyRmaHOcLsfrg3B3fpyBofuU4xbcbY5IiZpjAxrPRLu3IncX+63uPiG5drBsjlidUiICh4+E9r3at/Z71zzyp4AzGiKAf6laW0MLDwFALL1xj5eB+h51OAcxNusM7hpESyx9OJaVHo3OfreMWwrORaySAY2O0n1BL8HEUwVPlzeJ2QK5UaA+OW27zjQq/5Ktd0=";
        String pwd = "LJRYRPYF27466944";
        decode(1, text, pwd);
    }*/

}
